package com.example.factory.core.service.impl;

import com.example.factory.core.domain.UserEntity;
import com.example.factory.core.repository.UserRepository;
import com.example.factory.core.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Lei Tao
 */
@Service
public class UserServiceImpl implements UserService {
    private final UserRepository userRepository;

    public UserServiceImpl(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    @Override
    @Transactional
    public void deleteUser(String userGuid) {
        UserEntity userEntity = userRepository.findByGuidAndArchivedFalse(userGuid);
        userEntity.archived();
        userRepository.save(userEntity);
    }

    @Override
    @Transactional
    public void saveOrUpdate(UserEntity userEntity) {
        userRepository.save(userEntity);
    }
}
